<?php
header('content-type:text/html;charset=utf-8');	
	ini_set('date.timezone','Asia/Shanghai');
	require_once 'E:\test1\sites\default\backend\apis/Queue_Class.php';
	require_once 'E:\test1\sites\default\backend\apis/UpFile_ApiClient.class.php';
	//echo 'aaaaaaaa';
	$queue=new QueueClass();
	$code='';
	$code_str='';
	$order_sn='';
	
	$auth='fileflag_code';
	$api=new UpFile_ApiClient();
	$data=array('code'=>$code,'order_sn'=>$order_sn,'taskid'=>'','apiflag'=>'1','flag'=>'coprsys','method'=>'copr.update','type'=>'json','timestamp'=>time(),'charset'=>'utf-8','ver'=>1,'file_status'=>'');
	$url='http://copr.hucai.com/?a=apis.FileFlag_Code';
	$result=$api->DoRequest($url,$auth,$data);
	//var_dump($result);
	//echo 'aaaaaaaaa';
	//file_put_contents('code_value.txt',$result);
	
	if(get_magic_quotes_gpc())
		{
			stripslashes($result);
		}
	$result=json_decode(trim(urldecode($result),chr(239).chr(187).chr(191)),true);
	$count=count($result);
	//var_dump($result);
	//exit;
	
	if($count<=0 && empty($result))
		{
			exit;
		}
		else
			{
				for($i=0;$i<$count;$i++)
					{
						//var_dump($result[$i]['product_id']);
						$code=json_decode(trim($result[$i]['product_id'],chr(239).chr(187).chr(191)),true);//解压JSON数据
						
						//var_dump($code);
						$order_sn='';
						$order_sn=$code['order_sn'];
						for($j=0;$j<count($code['fileinfo']);$j++)
							{
								if(!empty($code['fileinfo'][$i])&& is_array($code['fileinfo'][$i]))
									{
										if(!empty($code['fileinfo'][$i]['code']))
											{
												$code_str.=','.number_format($code['fileinfo'][$i]['code'],'','','');
											}
										
									}
							}
						$code_str=trim($code_str,',');
						//echo $code_str;
						$queue->add_item($code_str);
					}
				
				for($i=0;$i<$count;$i++)
					{
						$cur=$queue->get_queue();
						//var_dump($cur);
						//exit;
						$code=$queue->del_item();
						$data=array('code'=>$code,'order_sn'=>$order_sn,'taskid'=>$result[$i]->id,'apiflag'=>'1','flag'=>'coprsys','method'=>'copr.update','type'=>'json','timestamp'=>time(),'charset'=>'utf-8','ver'=>1,'file_status'=>'');
						//var_dump($code);
						//file_put_contents('code_value.txt',$code);
						//var_dump($data);
						//exit;
						$url='http://copr.hucai.com/index.php?a=apis.FileFlag_Client';
						$result=$api->DoRequest($url,$auth,$data);
						echo '第 '.$i.' 条记录推送结果为：';
						var_dump($result);
						echo '<br/><br/>';
						exit;
						usleep(100);
					}
			}
			//var_dump($result);
			exit;


?>